{include file='public/header' /}
 <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="{:url('admin/index/main')}">首页</a>
        <a href="{:url('index')}">用户管理</a>
        <a>
          <cite>列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:40px">ဂ</i></a>
</div>
<div class="x-body">
<blockquote class="layui-elem-quote">
        <div class="layui-inline">
            <input class="layui-input" name="key" id="key" placeholder="请输入查询内容">
        </div>&nbsp;
     <button class="layui-btn btns" id="search" data-type="reload"><i class="layui-icon" style="color: #fff">&#xe615;</i>搜索</button>
     <button class="layui-btn" style="background:#00BFFF;" onclick="javascript:window.location.href='{:url('add')}'"><i class="layui-icon" style="color: #fff">&#xe654;</i>添加</button>
     <button class="layui-btn" id="delAll" style="background:#FF3030;"><i class="layui-icon" style="color: #fff">&#xe640;</i>批量删除</button>
</blockquote>
<table class="layui-hide" id="list" lay-filter="list"></table>
</div>
<script type="text/html" id="cate">
    {{# if(d.cate==1){ }}
       <span style="color: #35C4F9">管理员</span>
    {{# }else{  }}
       <span style="color: red">会员</span>
    {{# } }}
</script>
<script type="text/html" id="action">
    <a href="{:url('edit')}?uid={{d.uid}}" title="编辑"><i class="layui-icon" style="color: #5FB878;font-size: 20px;">&#xe642;</i></a>
    {{# if(d.uid!=1){ }}
    <a lay-event="del" title="删除"><i class="layui-icon" style="color:#FF5722;font-size: 20px;">&#xe640;</i></a>
    {{# }else{  }}
    {{# } }}
</script>
<script>
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form, $ = layui.jquery;
        var tableIn = table.render({
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            page: true,
            cols: [[
                {checkbox:true,fixed: true},
                {field: 'uid', title: '编号', width: 80, fixed: true,align: 'center'},
                {field: 'username', title: '用户名'},
                {field: 'email', title: '邮箱'},
                {field: 'regip', title: '注册IP地址'},
                {title: '权限',width:100, align: 'center', toolbar: '#cate'},
                {field: 'regdate', title: '注册时间',align: 'center'},
                {width: 160,title: '操作', align: 'center', toolbar: '#action'}
            ]],
            limit: 10, //每页默认显示的数量
            done:function(msg){
               /* console.log(msg.data);*/
            }
        });
        //搜索
        $('#search').on('click', function() {
            var key = $('#key').val();
            if($.trim(key)==='') {
                layer.msg('{:lang("pleaseEnter")}关键字！',{icon:0});
                return;
            }
            tableIn.reload({
                where: {key: key}
            })
        });
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('您确定要删除该会员吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('del')}",{uid:data.uid},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg('操作失败！',{time:1000,icon:2});
                        }
                    },'json');
                    layer.close(index);
                });
            }
        });

        $('#delAll').click(function(){
            layer.confirm('确认要删除选中信息吗？', {icon: 3}, function(index) {
                layer.close(index);
                var checkStatus = table.checkStatus('list'); //test即为参数uid设定的值
                var uids = [];
                $(checkStatus.data).each(function (i, o) {
                    uids.push(o.uid);
                });
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('delall')}", {uids: uids}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg, {time: 1000, icon: 1});
                        tableIn.reload();
                    } else {
                        layer.msg(data.msg, {time: 1000, icon: 2});
                    }
                },'json');
            });
        })
    });
</script>
